package com.dongchedi.config;

import com.dongchedi.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
 * @author leibidong
 * @description    注册拦截器进容器
 * @date 2021/6/23
 */
@Configuration
public class CorsConfig  extends WebMvcConfigurerAdapter {
  @Autowired
  LoginInterceptor loginInterceptor;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
                .allowCredentials(true).maxAge(6000);
    }
    //登录拦截注册
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/api/**") .excludePathPatterns("/css/**", "/js/**", "/img/**","/api/login");
//                .excludePathPatterns("/seengene/login")
//                .excludePathPatterns("/seengene/logindo");
    }

}

